#include <Servo.h>

Servo jxb_1;
Servo jxb_2;
Servo jxb_3;
Servo jxb_4;
int qh=90,sx=100,zy=85,kb=90;
void setup() {
  Serial.begin(9600);
  jxb_1.attach(3,500,2500);
  jxb_2.attach(5,500,2500);
  jxb_3.attach(6,500,2500);
  jxb_4.attach(9,500,2500);
  jxb_1.write(90);//0~90 90为张开
  delay(500);
  jxb_2.write(90);//90~180 后~前
  delay(500);
  jxb_3.write(100);//0~90  下~上
  delay(500);
  jxb_4.write(95);//0~180 左到右
  delay(500);
}
char text[32] ="";
//  jxb_1.write(90);
//  delay(500);
//  jxb_2.write(90);
//  delay(500);
//  jxb_3.write(100);
//  delay(500);
//  jxb_4.write(105);
//  delay(500);
void loop() {
    if(Serial.available())
    {
      //Serial.write(Serial.read());
      text[0]=Serial.read();
    if(text[0]=='l'){
      kb++;
      if(kb>=90)
      {
        kb=90;
      }
      Serial.println(kb);
      delay(200);
    }
    else if(text[0]=='m'){
      kb--;
      if(kb<=0)
      {
        kb=0;
      }
      Serial.println(kb);
      delay(200);
    }
    else if(text[0]=='a'){
      qh++;
      if(qh>=180)
      {
        qh=180;
      }
      Serial.println(qh);
      delay(200);
    }
    else if(text[0]=='b'){
      qh--;
      if(qh<=0)
      {
        qh=0;
      }
      Serial.println(qh);
      delay(200);
    }
    else if(text[0]=='e'){
      zy++;
      if(zy>=180)
      {
        zy=180;
      }
      Serial.println(zy);
      delay(200);
    }
    else if(text[0]=='f'){
      zy--;
      if(zy<=0)
      {
        zy=0;
      }
      Serial.println(zy);
      delay(200);
    }
    else if(text[0]=='c'){
      sx++;
      if(sx>=180)
      {
        sx=180;
      }
      Serial.println(sx);
      delay(200);
    }
    else if(text[0]=='d'){
      sx--;
      if(sx<=0)
      {
        sx=0;
      }
      Serial.println(sx);
      delay(200);
    }
    text[32]="";
    }
  jxb_1.write(kb);//0~90 90为张开
  delay(200);
  jxb_2.write(sx);
  delay(200);
  jxb_3.write(qh);
  delay(200);
  jxb_4.write(zy);
  delay(200);
}
